package com.pzhu.user.domain.dto.converter;

import com.pzhu.user.api.UserApi;
import com.pzhu.user.domain.ro.UserCreateRO;
import com.pzhu.user.domain.ro.UserSearchRO;
import com.pzhu.user.domain.vo.RolePermissionCollectionVo;
import com.pzhu.user.domain.vo.UserSearchVO;
import org.mapstruct.*;

@Mapper(
        componentModel = MappingConstants.ComponentModel.SPRING,
        nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS,
        unmappedTargetPolicy = ReportingPolicy.IGNORE,
        collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED)
public interface UserDtoConverter {

    UserCreateRO convert(UserApi.UserCreateDTO userDTO);

    @Mapping(target = "username", ignore = true)
    @Mapping(target = "phone", ignore = true)
    @Mapping(target = "email", ignore = true)
    UserSearchRO byIdConverter(UserApi.GetUserRequest request);

    @Mapping(target = "roles", source = "userAllRoles.roleList")
    @Mapping(target = "perms", source = "userAllRoles.permissionList")
    UserApi.UserDTO searchRespToDTO(UserSearchVO userSearchVO, RolePermissionCollectionVo userAllRoles);

    UserSearchRO byUserNameConverter(UserApi.GetUserByUsernameRequest request);

    UserSearchRO byEmailConverter(UserApi.GetUserByEmailRequest request);

    UserSearchRO byPhoneConverter(UserApi.GetUserByPhoneRequest request);
}
